<template>
  <div>
    <!-- 用户列表区域 -->
    <el-table :data="tableData" border stripe>
      <el-table-column type="index"></el-table-column>
      <!-- （从后台获取数据）动态渲染的表格列 -->
      <template v-for="(titleList, index) in titleList" >
        <!-- 转换时间格式 -->
        <el-table-column v-if="titleList.prop=='create_time'" :key="index" :label="titleList.label">
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column v-else :key="index" :prop="titleList.prop" :label="titleList.label"></el-table-column>
      </template>
      <el-table-column label="状态" v-if="state">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.mg_state" @change="stateChanged(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <slot name="line"></slot>
      <!-- 列 插槽，传值：row -->

      <el-table-column label="操作" width="200px">
        <template slot-scope="scope">
          <slot name="btn1" :row="scope.row"></slot>
          <!-- 操作按钮插槽，传值：row -->
          <slot name="btn2" :row="scope.row"></slot>
          <slot name="btn3" :row="scope.row"></slot>
          <slot name="btn4" :row="scope.row"></slot>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="queryInfo.total"
    ></el-pagination>
  </div>
</template> 

<script>
export default {
  data() {
    return {};
  },
  props: {
    tableData: Array, //表格数据
    titleList: Array, //表头数据
    queryInfo: Object, //分页数据
    state: {
      //调用状态拉块
      type: Boolean,
      default: false
    }
  },
  created() {
    console.log("+++++", this.queryInfo);
  },
  watch: {
  },
  methods: {
    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      // console.log(newSize)
      this.queryInfo.pagesize = newSize;
      this.$emit("getTableData"); //重新渲染数据的回调函数
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      console.log(newPage);
      this.queryInfo.pagenum = newPage;
      
      this.$emit("getTableData"); //重新渲染数据的回调函数
    },
    stateChanged(row) {
      this.$emit("stateChanged", row); //改变状态拉条的 回调函数stateChanged 参数：row
    }
  }
};
</script>

<style>
</style>